<?php
/*
 * @Author: 莫莫
 * @Phone: 13450159681
 * @Description: 
 * @Date: 2024-09-21 16:48:33
 * @LastEditTime: 2024-09-27 16:44:08
 */

namespace app\admin\controller\qingdongwms\finance;

use addons\qingdongwms\model\Staff;
use app\admin\controller\qingdongwms\Base;
use app\common\controller\Backend;

/**
 * 工资单
 *
 * @icon fa fa-circle-o
 */
class StaffWage extends Base
{
    
    /**
     * StaffWage模型对象
     * @var \addons\qingdongwms\model\StaffWage
     */
    protected $model = null;
    protected $searchFields = 'id,name';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \addons\qingdongwms\model\StaffWage();
        // $num = $this->model->getNum();
        // $this->view->assign('number',$num);
    }
    // https://qingyu.etor.com.cn/vQfjSyNeFc.php/qingdongwms/finance/wage?ref=addtabs
    // https://qingyu.etor.com.cn/vQfjSyNeFc.php/qingdongwms/finance/Invoice?ref=addtabs

    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                    ->with(['staff'])
                    ->where($where)
                    ->order($sort, $order)
                    ->paginate($limit);


            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }

    /**
     * 获取客户列表
     */
    public function getstaff()
    {
        $pageSize = input('pageSize');
        $pageNumber = input('pageNumber');
        $where = [];
        if ($keyValue = $this->request->request("keyValue")) {
            $where['id'] = ['in', explode(',', $keyValue)];
        }
        if(empty($pageSize) && empty($keyValue)){
            return json(Staff::where($where)->field('id,name')->select());
        }
        $name = input('name');
        if (!empty($name)) {
            $where['name'] = ['like', '%' . $name . '%'];
        }
        $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
        return json(['list' => $customer->items(), 'total' => $customer->total()]);
    }
    public function cashier(){
        $ids=input('ids');
        if(empty($ids)){
            $this->error('参数错误');
        }
        $ids = rtrim($ids,']');
        $ids = ltrim($ids,'[');
        $ids=explode(',',$ids);
        $this->model->where(['id'=>['in',$ids]])->update(['status'=>1]);
        $this->success('操作成功');
    }
}
